#include "bsp_g3507std.h"
#include "ti_msp_dl_config.h"
#include "user_main.h"


uint32_t g_g3507_board_order_array[G3507_BOARD_ORDER_ARRAY_LEN];
uint32_t g_g3507_board_sensor_array[G3507_BOARD_SENSOR_ARRAY_LEN];

////////////////////////////////////
////////////////////////////////////
//dac
const uint16_t gOutput_low[64] = {0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,0,0};

const uint16_t gOutputSignalSine64[64] = {2048, 2248, 2447, 2642, 2831, 3013,
    3185, 3347, 3496, 3631, 3750, 3854, 3940, 4007, 4056, 4086, 4095, 4086,
    4056, 4007, 3940, 3854, 3750, 3631, 3496, 3347, 3185, 3013, 2831, 2642,
    2447, 2248, 2048, 1847, 1648, 1453, 1264, 1082, 910, 748, 599, 464, 345,
    241, 155, 88, 39, 9, 0, 9, 39, 88, 155, 241, 345, 464, 599, 748, 910, 1082,
    1264, 1453, 1648, 1847};

const uint16_t gOutput_high[64] = {4095,4095,4095,4095,4095,4095,4095,
    4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,
    4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,
    4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,
    4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095,4095};

const uint16_t *goOutputs[] = {gOutput_low, gOutput_high, gOutputSignalSine64};

void dac_dma_output_sinesignal(const uint16_t * outputsignalsine64, uint32_t len)
{
    DL_DMA_disableChannel(DMA, DMA_CH0_CHAN_ID);

        /* Configure DMA source, destination and size */
    DL_DMA_setSrcAddr(DMA, DMA_CH0_CHAN_ID, (uint32_t) outputsignalsine64);
    DL_DMA_setDestAddr(DMA, DMA_CH0_CHAN_ID, (uint32_t) & (DAC0->DATA0));
    DL_DMA_setTransferSize(DMA, DMA_CH0_CHAN_ID, len);

    DL_DMA_enableChannel(DMA, DMA_CH0_CHAN_ID);
}

int g3507_board_get_sensor( uint32_t *board_sensor_array , uint32_t board_sensor_array_len  )
{

    return 0;
}

int g3507_board_set_order( uint32_t *board_order_array  , uint32_t board_order_array_len  )
{
    dac_dma_output_sinesignal(goOutputs[board_order_array[0]], 64);
    return 0;
}
